home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / exerion.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  18KB  |  519 lines

  1. /***************************************************************************
  2.  
  3. Exerion by Jaleco
  4.  
  5. Exerion is a unique driver in that it has idiosyncracies that are straight
  6. out of Bizarro World. I submit for your approval:
  7.  
  8. * The mystery reads from $d802 - timer-based protection?
  9. * The freakish graphics encoding scheme, which no other MAME-supported game uses
  10. * The sprite-ram, and all the funky parameters that go along with it
  11. * The unusual parallaxed background. Is it controlled by the 2nd CPU?
  12.  
  13. ***************************************************************************/
  14.  
  15. #include "driver.h"
  16. #include "vidhrdw/generic.h"
  17.  
  18.  
  19. void exerion_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, const unsigned char *color_prom);
  20. int exerion_vh_start(void);
  21. void exerion_vh_stop(void);
  22. void exerion_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh);
  23.  
  24. WRITE_HANDLER( exerion_videoreg_w );
  25. WRITE_HANDLER( exerion_video_latch_w );
  26. READ_HANDLER( exerion_video_timing_r );
  27.  
  28. extern UINT8 exerion_cocktail_flip;
  29.  
  30.  
  31. /*********************************************************************
  32.  * Interrupts & inputs
  33.  *********************************************************************/
  34.  
  35. static READ_HANDLER( exerion_port01_r )
  36. {
  37.     /* the cocktail flip bit muxes between ports 0 and 1 */
  38.     return exerion_cocktail_flip ? input_port_1_r(offset) : input_port_0_r(offset);
  39. }
  40.  
  41.  
  42. static READ_HANDLER( exerion_port3_r )
  43. {
  44.     /* bit 0 is VBLANK, which we simulate manually */
  45.     int result = input_port_3_r(offset);
  46.     int ybeam = cpu_getscanline();
  47.     if (ybeam > Machine->drv->visible_area.max_y)
  48.         result |= 1;
  49.     return result;
  50. }
  51.  
  52.  
  53. static int exerion_interrupt(void)
  54. {
  55.     /* Exerion triggers NMIs on coin insertion */
  56.     if (readinputport(4) & 1)
  57.         return nmi_interrupt();
  58.     else return ignore_interrupt();
  59. }
  60.  
  61.  
  62.  
  63. /*********************************************************************
  64.  * Protection??
  65.  *********************************************************************/
  66.  
  67. /* This is the first of many Exerion "features." No clue if it's */
  68. /* protection or some sort of timer. */
  69. static UINT8 porta;
  70. static UINT8 portb;
  71.  
  72. static READ_HANDLER( exerion_porta_r )
  73. {
  74.     porta ^= 0x40;
  75.     return porta;
  76. }
  77.  
  78. static WRITE_HANDLER( exerion_portb_w )
  79. {
  80.     /* pull the expected value from the ROM */
  81.     porta = memory_region(REGION_CPU1)[0x5f76];
  82.     portb = data;
  83.  
  84.     logerror("Port B = %02X\n", data);
  85. }
  86.  
  87. static READ_HANDLER( exerion_protection_r )
  88. {
  89.     UINT8 *RAM = memory_region(REGION_CPU1);
  90.  
  91.     if (cpu_get_pc() == 0x4143)
  92.         return RAM[0x33c0 + (RAM[0x600d] << 2) + offset];
  93.     else
  94.         return RAM[0x6008 + offset];
  95. }
  96.  
  97.  
  98.  
  99. /*********************************************************************
  100.  * CPU memory structures
  101.  *********************************************************************/
  102.  
  103. static struct MemoryReadAddress readmem[] =
  104. {
  105.     { 0x0000, 0x5fff, MRA_ROM },
  106.     { 0x6008, 0x600b, exerion_protection_r },
  107.     { 0x6000, 0x67ff, MRA_RAM },
  108.     { 0x8000, 0x8bff, MRA_RAM },
  109.     { 0xa000, 0xa000, exerion_port01_r },
  110.     { 0xa800, 0xa800, input_port_2_r },
  111.     { 0xb000, 0xb000, exerion_port3_r },
  112.     { 0xd802, 0xd802, AY8910_read_port_1_r },
  113.     { -1 }  /* end of table */
  114. };
  115.  
  116.  
  117. static struct MemoryWriteAddress writemem[] =
  118. {
  119.     { 0x0000, 0x5fff, MWA_ROM },
  120.     { 0x6000, 0x67ff, MWA_RAM },
  121.     { 0x8000, 0x87ff, videoram_w, &videoram, &videoram_size },
  122.     { 0x8800, 0x887f, MWA_RAM, &spriteram, &spriteram_size },
  123.     { 0x8800, 0x8bff, MWA_RAM },
  124.     { 0xc000, 0xc000, exerion_videoreg_w },
  125.     { 0xc800, 0xc800, soundlatch_w },
  126.     { 0xd000, 0xd000, AY8910_control_port_0_w },
  127.     { 0xd001, 0xd001, AY8910_write_port_0_w },
  128.     { 0xd800, 0xd800, AY8910_control_port_1_w },
  129.     { 0xd801, 0xd801, AY8910_write_port_1_w },
  130.     { -1 }  /* end of table */
  131. };
  132.  
  133.  
  134. static struct MemoryReadAddress cpu2_readmem[] =
  135. {
  136.     { 0x0000, 0x1fff, MRA_ROM },
  137.     { 0x4000, 0x47ff, MRA_RAM },
  138.     { 0x6000, 0x6000, soundlatch_r },
  139.     { 0xa000, 0xa000, exerion_video_timing_r },
  140.     { -1 }  /* end of table */
  141. };
  142.  
  143.  
  144. static struct MemoryWriteAddress cpu2_writemem[] =
  145. {
  146.     { 0x0000, 0x1fff, MWA_ROM },
  147.     { 0x4000, 0x47ff, MWA_RAM },
  148.     { 0x8000, 0x800c, exerion_video_latch_w },
  149.     { -1 }  /* end of table */
  150. };
  151.  
  152.  
  153.  
  154. /*********************************************************************
  155.  * Input port definitions
  156.  *********************************************************************/
  157.  
  158. INPUT_PORTS_START( exerion )
  159.     PORT_START      /* player 1 inputs (muxed on 0xa000) */
  160.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER1 )
  161.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER1 )
  162.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER1 )
  163.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER1 )
  164.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  165.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  166.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 )
  167.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START2 )
  168.  
  169.     PORT_START      /* player 2 inputs (muxed on 0xa000) */
  170.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
  171.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
  172.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
  173.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
  174.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  175.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  176.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 )
  177.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START2 )
  178.  
  179.     PORT_START      /* dip switches (0xa800) */
  180.     PORT_DIPNAME( 0x07, 0x02, DEF_STR( Lives ) )
  181.     PORT_DIPSETTING(    0x00, "1" )
  182.     PORT_DIPSETTING(    0x01, "2" )
  183.     PORT_DIPSETTING(    0x02, "3" )
  184.     PORT_DIPSETTING(    0x03, "4" )
  185.     PORT_DIPSETTING(    0x04, "5" )
  186.     PORT_BITX(0,        0x07, IPT_DIPSWITCH_SETTING | IPF_CHEAT, "Infinite", IP_KEY_NONE, IP_JOY_NONE )
  187.     PORT_DIPNAME( 0x18, 0x00, DEF_STR( Bonus_Life ) )
  188.     PORT_DIPSETTING(    0x00, "10000" )
  189.     PORT_DIPSETTING(    0x08, "20000" )
  190.     PORT_DIPSETTING(    0x10, "30000" )
  191.     PORT_DIPSETTING(    0x18, "40000" )
  192.     PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )      /* used */
  193.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  194.     PORT_DIPSETTING(    0x20, DEF_STR( On ) )
  195.     PORT_DIPNAME( 0x40, 0x00, DEF_STR( Difficulty ) )
  196.     PORT_DIPSETTING(    0x00, "Easy" )
  197.     PORT_DIPSETTING(    0x40, "Hard" )
  198.     PORT_DIPNAME( 0x80, 0x00, DEF_STR( Cabinet ) )
  199.     PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
  200.     PORT_DIPSETTING(    0x80, DEF_STR( Cocktail ) )
  201.  
  202.     PORT_START      /* dip switches/VBLANK (0xb000) */
  203.     PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED )        /* VBLANK */
  204.     PORT_DIPNAME( 0x02, 0x00, DEF_STR( Unknown ) )
  205.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  206.     PORT_DIPSETTING(    0x02, DEF_STR( On ) )
  207.     PORT_DIPNAME( 0x0c, 0x00, DEF_STR( Coinage ) )
  208.     PORT_DIPSETTING(    0x00, DEF_STR( 1C_1C ) )
  209.     PORT_DIPSETTING(    0x04, DEF_STR( 1C_2C ) )
  210.     PORT_DIPSETTING(    0x08, DEF_STR( 1C_3C ) )
  211.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_4C ) )
  212.     PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
  213.  
  214.     PORT_START      /* FAKE */
  215.     /* The coin slots are not memory mapped. */
  216.     /* This fake input port is used by the interrupt */
  217.     /* handler to be notified of coin insertions. We use IMPULSE to */
  218.     /* trigger exactly one interrupt, without having to check when the */
  219.     /* user releases the key. */
  220.     PORT_BIT_IMPULSE( 0x01, IP_ACTIVE_HIGH, IPT_COIN1, 1 )
  221. INPUT_PORTS_END
  222.  
  223.  
  224.  
  225. /*********************************************************************
  226.  * Graphics layouts
  227.  *********************************************************************/
  228.  
  229. static struct GfxLayout charlayout =
  230. {
  231.     8,8,            /* 8*8 characters */
  232.     512,          /* total number of chars */
  233.     2,              /* 2 bits per pixel (# of planes) */
  234.     { 0, 4 },       /* start of every bitplane */
  235.     { 3, 2, 1, 0, 8+3, 8+2, 8+1, 8+0 },
  236.     { 16*0, 16*1, 16*2, 16*3, 16*4, 16*5, 16*6, 16*7 },
  237.     16*8            /* every char takes 16 consecutive bytes */
  238. };
  239.  
  240. /* 16 x 16 sprites -- requires reorganizing characters in init_exerion() */
  241. static struct GfxLayout spritelayout =
  242. {
  243.     16,16,          /* 16*16 sprites */
  244.     128*2,          /* total number of sprites in the rom */
  245.     2,              /* 2 bits per pixel (# of planes) */
  246.     { 0, 4 },       /* start of every bitplane */
  247.     {  3, 2, 1, 0, 8+3, 8+2, 8+1, 8+0,
  248.             16+3, 16+2, 16+1, 16+0, 24+3, 24+2, 24+1, 24+0 },
  249.     { 32*0, 32*1, 32*2, 32*3, 32*4, 32*5, 32*6, 32*7,
  250.             32*8, 32*9, 32*10, 32*11, 32*12, 32*13, 32*14, 32*15 },
  251.     64*8            /* every sprite takes 64 consecutive bytes */
  252. };
  253.  
  254. /* Quick and dirty way to emulate pixel-doubled sprites. */
  255. static struct GfxLayout bigspritelayout =
  256. {
  257.     32,32,          /* 32*32 sprites */
  258.     128*2,          /* total number of sprites in the rom */
  259.     2,              /* 2 bits per pixel (# of planes) */
  260.     { 0, 4 },       /* start of every bitplane */
  261.     {  3, 3, 2, 2, 1, 1, 0, 0,
  262.             8+3, 8+3, 8+2, 8+2, 8+1, 8+1, 8+0, 8+0,
  263.             16+3, 16+3, 16+2, 16+2, 16+1, 16+1, 16+0, 16+0,
  264.             24+3, 24+3, 24+2, 24+2, 24+1, 24+1, 24+0, 24+0 },
  265.     { 32*0, 32*0, 32*1, 32*1, 32*2, 32*2, 32*3, 32*3,
  266.             32*4, 32*4, 32*5, 32*5, 32*6, 32*6, 32*7, 32*7,
  267.             32*8, 32*8, 32*9, 32*9, 32*10, 32*10, 32*11, 32*11,
  268.             32*12, 32*12, 32*13, 32*13, 32*14, 32*14, 32*15, 32*15 },
  269.     64*8            /* every sprite takes 64 consecutive bytes */
  270. };
  271.  
  272. static struct GfxDecodeInfo gfxdecodeinfo[] =
  273. {
  274.     { REGION_GFX1, 0, &charlayout,         0, 64 },
  275.     { REGION_GFX2, 0, &spritelayout,     256, 64 },
  276.     { REGION_GFX2, 0, &bigspritelayout,  256, 64 },
  277.     { -1 } /* end of array */
  278. };
  279.  
  280.  
  281.  
  282. /*********************************************************************
  283.  * Sound interfaces
  284.  *********************************************************************/
  285.  
  286. static struct AY8910interface ay8910_interface =
  287. {
  288.     2,  /* 2 chips */
  289.     10000000/6, /* 1.666 MHz */
  290.     { 30, 30 },
  291.     { 0, exerion_porta_r },
  292.     { 0 },
  293.     { 0 },
  294.     { 0, exerion_portb_w }
  295. };
  296.  
  297.  
  298.  
  299. /*********************************************************************
  300.  * Machine driver
  301.  *********************************************************************/
  302.  
  303. static struct MachineDriver machine_driver_exerion =
  304. {
  305.     /* basic machine hardware */
  306.     {
  307.         {
  308.             CPU_Z80,
  309.             10000000/3, /* 3.333 MHz */
  310.             readmem,writemem,0,0,
  311.             exerion_interrupt,1
  312.         },
  313.         {
  314.             CPU_Z80,
  315.             10000000/3, /* 3.333 MHz */
  316.             cpu2_readmem,cpu2_writemem,0,0,
  317.             ignore_interrupt,0
  318.         }
  319.     },
  320.     60, 0,  /* frames per second, vblank duration */
  321.     1,  /* 1 CPU slice per frame - interleaving is forced when a sound command is written */
  322.     0,
  323.  
  324.     /* video hardware */
  325.     64*8, 32*8, { 12*8, 52*8-1, 2*8, 30*8-1 },
  326.     gfxdecodeinfo,
  327.     32,256*3,
  328.     exerion_vh_convert_color_prom,
  329.  
  330.     VIDEO_TYPE_RASTER,
  331.     0,
  332.     exerion_vh_start,
  333.     exerion_vh_stop,
  334.     exerion_vh_screenrefresh,
  335.  
  336.     /* sound hardware */
  337.     0,0,0,0,
  338.     {
  339.         {
  340.             SOUND_AY8910,
  341.             &ay8910_interface
  342.         }
  343.     }
  344. };
  345.  
  346.  
  347.  
  348. /*********************************************************************
  349.  * ROM definitions
  350.  *********************************************************************/
  351.  
  352. ROM_START( exerion )
  353.     ROM_REGION( 0x10000, REGION_CPU1 )     /* 64k for code */
  354.     ROM_LOAD( "exerion.07",   0x0000, 0x2000, 0x4c78d57d )
  355.     ROM_LOAD( "exerion.08",   0x2000, 0x2000, 0xdcadc1df )
  356.     ROM_LOAD( "exerion.09",   0x4000, 0x2000, 0x34cc4d14 )
  357.  
  358.     ROM_REGION( 0x10000, REGION_CPU2 )     /* 64k for the second CPU */
  359.     ROM_LOAD( "exerion.05",   0x0000, 0x2000, 0x32f6bff5 )
  360.  
  361.     ROM_REGION( 0x02000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  362.     ROM_LOAD( "exerion.06",   0x00000, 0x2000, 0x435a85a4 ) /* fg chars */
  363.  
  364.     ROM_REGION( 0x04000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  365.     ROM_LOAD( "exerion.11",   0x00000, 0x2000, 0xf0633a09 ) /* sprites */
  366.     ROM_LOAD( "exerion.10",   0x02000, 0x2000, 0x80312de0 )
  367.  
  368.     ROM_REGION( 0x08000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  369.     ROM_LOAD( "exerion.03",   0x00000, 0x2000, 0x790595b8 ) /* bg data */
  370.     ROM_LOAD( "exerion.04",   0x02000, 0x2000, 0xd7abd0b9 )
  371.     ROM_LOAD( "exerion.01",   0x04000, 0x2000, 0x5bb755cb )
  372.     ROM_LOAD( "exerion.02",   0x06000, 0x2000, 0xa7ecbb70 )
  373.  
  374.     ROM_REGION( 0x0420, REGION_PROMS )
  375.     ROM_LOAD( "exerion.e1",   0x0000, 0x0020, 0x2befcc20 ) /* palette */
  376.     ROM_LOAD( "exerion.i8",   0x0020, 0x0100, 0x31db0e08 ) /* fg char lookup table */
  377.     ROM_LOAD( "exerion.h10",  0x0120, 0x0100, 0xcdd23f3e ) /* sprite lookup table */
  378.     ROM_LOAD( "exerion.i3",   0x0220, 0x0100, 0xfe72ab79 ) /* bg char lookup table */
  379.     ROM_LOAD( "exerion.k4",   0x0320, 0x0100, 0xffc2ba43 ) /* bg char mixer */
  380. ROM_END
  381.  
  382. ROM_START( exeriont )
  383.     ROM_REGION( 0x10000, REGION_CPU1 )     /* 64k for code */
  384.     ROM_LOAD( "prom5.4p",     0x0000, 0x4000, 0x58b4dc1b )
  385.     ROM_LOAD( "prom6.4s",     0x4000, 0x2000, 0xfca18c2d )
  386.  
  387.     ROM_REGION( 0x10000, REGION_CPU2 )     /* 64k for the second CPU */
  388.     ROM_LOAD( "exerion.05",   0x0000, 0x2000, 0x32f6bff5 )
  389.  
  390.     ROM_REGION( 0x02000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  391.     ROM_LOAD( "exerion.06",   0x00000, 0x2000, 0x435a85a4 ) /* fg chars */
  392.  
  393.     ROM_REGION( 0x04000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  394.     ROM_LOAD( "exerion.11",   0x00000, 0x2000, 0xf0633a09 ) /* sprites */
  395.     ROM_LOAD( "exerion.10",   0x02000, 0x2000, 0x80312de0 )
  396.  
  397.     ROM_REGION( 0x08000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  398.     ROM_LOAD( "exerion.03",   0x00000, 0x2000, 0x790595b8 ) /* bg data */
  399.     ROM_LOAD( "exerion.04",   0x02000, 0x2000, 0xd7abd0b9 )
  400.     ROM_LOAD( "exerion.01",   0x04000, 0x2000, 0x5bb755cb )
  401.     ROM_LOAD( "exerion.02",   0x06000, 0x2000, 0xa7ecbb70 )
  402.  
  403.     ROM_REGION( 0x0420, REGION_PROMS )
  404.     ROM_LOAD( "exerion.e1",   0x0000, 0x0020, 0x2befcc20 ) /* palette */
  405.     ROM_LOAD( "exerion.i8",   0x0020, 0x0100, 0x31db0e08 ) /* fg char lookup table */
  406.     ROM_LOAD( "exerion.h10",  0x0120, 0x0100, 0xcdd23f3e ) /* sprite lookup table */
  407.     ROM_LOAD( "exerion.i3",   0x0220, 0x0100, 0xfe72ab79 ) /* bg char lookup table */
  408.     ROM_LOAD( "exerion.k4",   0x0320, 0x0100, 0xffc2ba43 ) /* bg char mixer */
  409. ROM_END
  410.  
  411. ROM_START( exerionb )
  412.     ROM_REGION( 0x10000, REGION_CPU1 )     /* 64k for code */
  413.     ROM_LOAD( "eb5.bin",      0x0000, 0x4000, 0xda175855 )
  414.     ROM_LOAD( "eb6.bin",      0x4000, 0x2000, 0x0dbe2eff )
  415.  
  416.     ROM_REGION( 0x10000, REGION_CPU2 )     /* 64k for the second CPU */
  417.     ROM_LOAD( "exerion.05",   0x0000, 0x2000, 0x32f6bff5 )
  418.  
  419.     ROM_REGION( 0x02000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  420.     ROM_LOAD( "exerion.06",   0x00000, 0x2000, 0x435a85a4 ) /* fg chars */
  421.  
  422.     ROM_REGION( 0x04000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  423.     ROM_LOAD( "exerion.11",   0x00000, 0x2000, 0xf0633a09 ) /* sprites */
  424.     ROM_LOAD( "exerion.10",   0x02000, 0x2000, 0x80312de0 )
  425.  
  426.     ROM_REGION( 0x08000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  427.     ROM_LOAD( "exerion.03",   0x00000, 0x2000, 0x790595b8 ) /* bg data */
  428.     ROM_LOAD( "exerion.04",   0x02000, 0x2000, 0xd7abd0b9 )
  429.     ROM_LOAD( "exerion.01",   0x04000, 0x2000, 0x5bb755cb )
  430.     ROM_LOAD( "exerion.02",   0x06000, 0x2000, 0xa7ecbb70 )
  431.  
  432.     ROM_REGION( 0x0420, REGION_PROMS )
  433.     ROM_LOAD( "exerion.e1",   0x0000, 0x0020, 0x2befcc20 ) /* palette */
  434.     ROM_LOAD( "exerion.i8",   0x0020, 0x0100, 0x31db0e08 ) /* fg char lookup table */
  435.     ROM_LOAD( "exerion.h10",  0x0120, 0x0100, 0xcdd23f3e ) /* sprite lookup table */
  436.     ROM_LOAD( "exerion.i3",   0x0220, 0x0100, 0xfe72ab79 ) /* bg char lookup table */
  437.     ROM_LOAD( "exerion.k4",   0x0320, 0x0100, 0xffc2ba43 ) /* bg char mixer */
  438. ROM_END
  439.  
  440.  
  441.  
  442. /*********************************************************************
  443.  * Initialization routines
  444.  *********************************************************************/
  445.  
  446. static void init_exerion(void)
  447. {
  448.     UINT32 oldaddr, newaddr, length;
  449.     UINT8 *src, *dst, *temp;
  450.  
  451.     /* allocate some temporary space */
  452.     temp = malloc(0x8000);
  453.     if (!temp)
  454.         return;
  455.  
  456.     /* make a temporary copy of the character data */
  457.     src = temp;
  458.     dst = memory_region(REGION_GFX1);
  459.     length = memory_region_length(REGION_GFX1);
  460.     memcpy(src, dst, length);
  461.  
  462.     /* decode the characters */
  463.     /* the bits in the ROM are ordered: n8-n7 n6 n5 n4-v2 v1 v0 n3-n2 n1 n0 h2 */
  464.     /* we want them ordered like this:  n8-n7 n6 n5 n4-n3 n2 n1 n0-v2 v1 v0 h2 */
  465.     for (oldaddr = 0; oldaddr < length; oldaddr++)
  466.     {
  467.         newaddr = ((oldaddr     ) & 0x1f00) |       /* keep n8-n4 */
  468.                   ((oldaddr << 3) & 0x00f0) |       /* move n3-n0 */
  469.                   ((oldaddr >> 4) & 0x000e) |       /* move v2-v0 */
  470.                   ((oldaddr     ) & 0x0001);        /* keep h2 */
  471.         dst[newaddr] = src[oldaddr];
  472.     }
  473.  
  474.     /* make a temporary copy of the sprite data */
  475.     src = temp;
  476.     dst = memory_region(REGION_GFX2);
  477.     length = memory_region_length(REGION_GFX2);
  478.     memcpy(src, dst, length);
  479.  
  480.     /* decode the sprites */
  481.     /* the bits in the ROMs are ordered: n3 n7-n6 n5 n4 v3-v2 v1 v0 n2-n1 n0 h3 h2 */
  482.     /* we want them ordered like this:   n7 n6-n5 n4 n3 n2-n1 n0 v3 v2-v1 v0 h3 h2 */
  483.     for (oldaddr = 0; oldaddr < length; oldaddr++)
  484.     {
  485.         newaddr = ((oldaddr << 1) & 0x3c00) |       /* move n7-n4 */
  486.                   ((oldaddr >> 4) & 0x0200) |       /* move n3 */
  487.                   ((oldaddr << 4) & 0x01c0) |       /* move n2-n0 */
  488.                   ((oldaddr >> 3) & 0x003c) |       /* move v3-v0 */
  489.                   ((oldaddr     ) & 0x0003);        /* keep h3-h2 */
  490.         dst[newaddr] = src[oldaddr];
  491.     }
  492.  
  493.     free(temp);
  494. }
  495.  
  496.  
  497. static void init_exerionb(void)
  498. {
  499.     UINT8 *ram = memory_region(REGION_CPU1);
  500.     int addr;
  501.  
  502.     /* the program ROMs have data lines D1 and D2 swapped. Decode them. */
  503.     for (addr = 0; addr < 0x6000; addr++)
  504.         ram[addr] = (ram[addr] & 0xf9) | ((ram[addr] & 2) << 1) | ((ram[addr] & 4) >> 1);
  505.  
  506.     /* also convert the gfx as in Exerion */
  507.     init_exerion();
  508. }
  509.  
  510.  
  511.  
  512. /*********************************************************************
  513.  * Game drivers
  514.  *********************************************************************/
  515.  
  516. GAMEX( 1983, exerion,  0,       exerion, exerion, exerion,  ROT90, "Jaleco", "Exerion", GAME_IMPERFECT_COLORS )
  517. GAMEX( 1983, exeriont, exerion, exerion, exerion, exerion,  ROT90, "Jaleco (Taito America license)", "Exerion (Taito)", GAME_IMPERFECT_COLORS )
  518. GAMEX( 1983, exerionb, exerion, exerion, exerion, exerionb, ROT90, "Jaleco", "Exerion (bootleg)", GAME_IMPERFECT_COLORS )
  519.